package kr.hkit.powerjava.chapter22.work;

import java.util.ArrayList;
import java.util.StringTokenizer;

import javax.swing.JOptionPane;

public class TestMain {
	public static void main(String[] args) {
		ArrayList<Student> stdList = new ArrayList<>();
		initList(stdList);
		StudentManager sm = new StudentManager(stdList);
		Student std=null;
		int res = 0;
		do {
			try {
				res = Integer.parseInt(JOptionPane
						.showInputDialog("1.추가 2.검색 3.수정 4.삭제 5.리스트 6. 종료"));
			} catch (NumberFormatException e) {
				res = 6;
			}
			switch (res) {
				case 1:
					std = inputStdInfo(true);
					sm.addStudent(std);
					break;
				case 2:
					std = sm.searchStd(inputStdInfo(false));
					if (std==null){
						System.out.println("해당 학생 없음");
					}else{
						System.out.println(std);
					}
					break;
				case 3:
					std = inputStdInfo(true);
					sm.reStudent(std);
					break;
				case 4:
					std = inputStdInfo(false);
					sm.delStudent(std);
					break;
				case 5:
					sm.prnList();
					break;
				default:
					break;
			}
		} while (res < 6);

	}//end of main
	
	private static Student inputStdInfo(boolean gubun){
		if(gubun){
			String std = JOptionPane.showInputDialog("학생번호 성명 국어 영어 수학");
			StringTokenizer st = new StringTokenizer(std);
			int stdNum = Integer.parseInt(st.nextToken());
			String stdName = st.nextToken();
			int kor = Integer.parseInt(st.nextToken());
			int eng = Integer.parseInt(st.nextToken());
			int math = Integer.parseInt(st.nextToken());
			return new Student(stdNum, stdName, kor, eng, math);
		}else{
			String std = JOptionPane.showInputDialog("학생번호 성명");
			StringTokenizer st = new StringTokenizer(std);
			int stdNum = Integer.parseInt(st.nextToken());
			String stdName = st.nextToken();
			return new Student(stdNum, stdName);
		}
	}
	
	private static void initList(ArrayList<Student> stdList) {
		stdList.add(new Student(1, "김태희", 87, 87, 87));
		stdList.add(new Student(2, "이민정", 90, 87, 87));
		stdList.add(new Student(3, "이소은", 70, 70, 87));
		stdList.add(new Student(4, "김성민", 60, 65, 65));
		stdList.add(new Student(5, "이소정", 50, 55, 50));
		stdList.add(new Student(6, "김민정", 90, 87, 100));
	}
}